﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace ATM
{
    public partial class login : Form
    {
        private SqlConnection con;
        private SqlCommand cmd;
        private SqlDataReader reader;
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string conStr=ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            con = new SqlConnection(conStr);
            cmd = new SqlCommand("select Acc_PIN from TB_ACCOUNT where Acc_No='" + textBox1.Text + "'", con);
            con.Open();
            reader = cmd.ExecuteReader();
            reader.Read();


            try {
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    MessageBox.Show("Ban chua dien day du thong tin");
                }
                else {

                    if (textBox2.Text == reader.GetValue(0).ToString())
                    {
                        string tk = textBox1.Text;
                        MessageBox.Show("Dang nhap thanh cong");
                        main f = new main(tk);
                        f.Show();
                        this.Visible=false;
                    }
                    else
                    {
                        MessageBox.Show("Sai mat khau");
                    }
                }
            
            }
            catch(Exception ){

                MessageBox.Show("Tai khoan khong dung");
            
            }
            con.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
            System.Windows.Forms.Application.Exit();
            Dispose();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
